package com.heima.article.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.common.msg.UpDownMsg;
import org.springframework.stereotype.Service;

@Service
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {
    @Override
    public boolean updateStatus(UpDownMsg upDownMsg) {
        short enable = upDownMsg.getEnable();
        if (ObjectUtil.notEqual(enable, (short)0) && ObjectUtil.notEqual(enable, (short)1)){
            return false;
        }
        return lambdaUpdate()
                .eq(upDownMsg.getArticleId() != null, ApArticleConfig::getArticleId, upDownMsg.getArticleId())
                .set(ApArticleConfig::getIsDown, ObjectUtil.equals(upDownMsg.getEnable(), (short) 0))
                .update();
    }
}
